package com.zx.util;

import org.junit.Test;

import java.security.SecureRandom;
import java.util.Random;
import java.util.UUID;

/**
 * @author sunkai
 * @date 2022/8/17 0017 11:25
 * @mood zhou xun
 */
public class Uuid {
    public static String uid(){
        String uuid= UUID.randomUUID().toString().replace("-","");
       return uuid.substring(10);
    }

    public static String uid4(){
        String uuid= UUID.randomUUID().toString().replace("-","");
        return uuid.substring(0,4);
    }
    /**
     * 生成16位不重复的随机数，含数字+大小写
     * @return
     */
    public static String getGUID() {
        StringBuilder uid = new StringBuilder();
        //产生16位的强随机数
        Random rd = new SecureRandom();
        for (int i = 0; i < 8; i++) {
                    //0-9的随机数
                    uid.append(rd.nextInt(10));
        }
        return uid.toString();
    }
    @Test
    public void a(){
        System.out.println(Integer.parseInt(Uuid.getGUID()));
    }
}
